#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
long long T,ans,m,n,L,V,d[maxn],v[maxn],a[maxn],p[maxn];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    for(int k=1;k<=T;k++){
        ans=0;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++) cin>>p[i];
        sort(p+1,p+1+m);
        for(int i=1;i<=n;i++){
                if(v[i]>V&&p[m]>=d[i]) ans++;
        }
        if(ans!=0)   cout<<ans<<" "<<m-1<<endl;
        else cout<<ans<<" "<<m<<endl;
    }
    return 0;
}
//Physic.
